import config from './config';
import axios from "axios";

let baseURL = config.api.baseUrl;

let _axios = axios.create({
  baseURL: baseURL,
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json"
  },
  method: "post"
})

const sitemap = {
  path: 'sitemap.xml',
  hostname: config.site.host,
  cacheTime: 1000 * 60 * 60 * 24,
  gzip: true,
  generate: true,
  exclude: ['/404', '/my/*', '/post/*', '/verify'],
  defaults: {
    changefreq: 'always',
    lastmod: new Date()
  },
  routes: async () => {
    let routes = [{
      url: '/',
      changefreq: 'always',
      lastmod: new Date()
    }, {
      url: '/node/1',
      changefreq: 'always',
      lastmod: new Date()
    }];

    let {data} = await _axios.post('/sitemap/url');
    data.forEach(url => routes.push({
      url: url,
      changefreq: 'always',
      lastmod: new Date()
    }));
    return routes;
  }
}

export default sitemap;
